{{define "siginfo"}}
{{template "top" .}}

<div class="card shadow-sm">
  <div class="card-header">
    {{if .new}}
      New Signature Info
    {{else}}
      Edit Signature Info # {{.siginfo.ID}}
    {{end}}
  </div>
  <div class="card-body">
    {{if not .new}}
      <div class="alert alert-warning" role="alert">
        <p>
          You are editing a signature info. This is allowed, but generally not
          advised unless you are only changing the exporitation timestamp to be
          sooner than it already is.
        </p>
        <p class="mb-0">
          If you are rotating a key, it is better to create a second signature
          info with the new key version, and then set this one to expire in 7-10
          days (or a time advised by Apple and Google).
        </p>
      </div>
    {{end}}

    <form method="POST" action="/siginfo/{{.siginfo.ID}}" class="m-0 p-0">
      <div class="row g-3">
        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="signing-key" id="signing-key" value="{{.siginfo.SigningKey}}"
              placeholder="signing-key" class="form-control font-monospace">
            <label for="signing-key" class="form-label">Signing key</label>
          </div>
          <div class="form-text text-muted">
            The resource ID of the signing key. The exact format will be dependent
            on the Key Management System that you are using.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
          <input type="text" name="signing-key-id" id="signing-key-id" value="{{.siginfo.SigningKeyID}}"
            placeholder="Signing key ID" class="form-control font-monospace">
          <label for="signing-key-id" class="form-label">Signing key ID</label>
          </div>
          <div class="form-text text-muted">
            This will normally be the Mobile Country Code (<a
            href="https://en.wikipedia.org/wiki/Mobile_country_code"
            target="_blank">MCC</a>) for the region that your export covers.
            This should be coordinated with Google and Apple.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="signing-key-version" id="signing-key-version" value="{{.siginfo.SigningKeyVersion}}"
              placeholder="Signing key version" class="form-control font-monospace">
            <label for="signing-key-version" class="form-label">Signing key version</label>
          </div>
          <div class="form-text text-muted">
            The version of the signing key. Normally will be v1, but may change
            with key rotation.
          </div>
        </div>

        <div class="col-12">
          <div class="input-group">
            <div class="form-floating">
              <input type="date" id="enddate" name="end-date" value="{{.siginfo.HTMLEndDate}}"
                min="2020-05-01" max="2029-12-21" class="form-control" />
              <label for="from-date" class="form-label">Use until date</label>
            </div>
            <div class="form-floating">
              <input type="time" id="endtime" name="end-time" value="{{.siginfo.HTMLEndTime}}"
                class="form-control" />
              <label for="from-time" class="form-label">Use until time</label>
            </div>
            <a href="https://www.timeanddate.com/worldclock/timezone/utc" target="_BLANK"
              class="input-group-text text-decoration-none">UTC</a>
          </div>
          <div class="form-text text-muted">
            For Export Configurations that reference this key #, this signature
            will be added up until this date/time. If the time is blank, the key
            will end at 00:00 UTC on the day specified. <strong>Leave blank to use
            this key as long as it is attached to an export!</strong> Signature
            Infos cannot be deleted. Instead they are expired by setting an end
            date and time.
          </div>
        </div>

        {{if .public}}
          <div class="col-12">
            <label for="public-key" class="form-label">Public key</label>
            <pre id="public-key" class="font-monospace user-select-all bg-light border rounded p-3 mb-0">{{.public}}</pre>
            <div class="form-text text-muted">
              This is the public key PEM for the signing key resource ID above.
            </div>
          </div>
        {{end}}

        {{if .signature}}
          <div class="col-12">
            <label for="hello-world-signature" class="form-label">"Hello world" signature</label>
            <pre id="hello-world-signature" class="font-monospace user-select-all bg-light border rounded p-3 mb-0">{{.signature}}</pre>
            <div class="form-text text-muted">
              This is a signature for the string "hello world". This signature
              will change if you refresh the page, but all signatures are valid.
            </div>
          </div>
        {{end}}

        <div class="d-grid col-12">
          <button type="submit" class="btn btn-primary" value="save">Save changes</button>
        </div>
      </div>
    </form>
  </div>
</div>
{{template "bottom" .}}
{{end}}
